import prisma from "@/app/utils/prismadb";
import serverAuth from "@/app/utils/serverAuth";
import { NextResponse } from "next/server";



export const GET = async (req:Request)=>{
    try {
        await serverAuth();
        const url = new URL(req.url);
        const movieId = url.pathname.split("/").pop();
        if(!movieId){
            return NextResponse.json({ message:"Invalid ID" }, { status: 404 })
        }
         const movie = await prisma.movie.findUnique({
            where:{
                id:movieId
            }
         })
         if(!movie){
            return NextResponse.json({ message:"Invalid ID" }, { status: 404 })
        }
        return  NextResponse.json({ data: movie }, { status: 200 })
    } catch (error) {
        console.log('current',error)
        return NextResponse.json({ message:"Internal server error" }, { status: 400 })
    }

}




